package cn.quang.search.toolkit.component.items.impl.aggregation;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class ESAggregationColumn {
    private String column;
    private String alias;
    private ESAggregationFunctionEnum function;

    public ESAggregationColumn(String col, String alias, ESAggregationFunctionEnum function) {
        if(col.equals("*")){
            this.column = col;
        }else{
            this.column = col;
        }
        this.alias = alias;
        this.function = function;
    }

    public String getColumn() {
        return column;
    }

    public void setColumn(String column) {
        this.column = column;
    }

    public ESAggregationFunctionEnum getFunction() {
        return function;
    }

    public void setFunction(ESAggregationFunctionEnum function) {
        this.function = function;
    }

    public String getAlias() {
        return alias;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public String getAggregationSql(){
        ESAggregationFunctionEnum sql = this.function;
        List<String> joinedSqlList = new ArrayList<>();
        joinedSqlList.add(sql.getFunction().replace("?", this.column) + " as " + this.alias);
        return StringUtils.join(joinedSqlList, ", ");
    }
}
